public class CondAndExpression extends Expression
{
	public DataInfo dataInfo;
	
	private EqualExpression eqExpr;
	private int op;
	private CondAndExpression condAndExpr;
	
	public static final int LA = 1;

	public CondAndExpression()
	{

	}

	public CondAndExpression( EqualExpression eqExpr, int op, CondAndExpression condExpr ,DataInfo dataInfo)
	{
		this.eqExpr = eqExpr;
		this.op = op;
		this.condAndExpr = condExpr;
		
		this.dataInfo = dataInfo;
	}

	public String toString()
	{
		String ret = "ConditionalAndExpression\n";

		String s = "";
		s += "| " + eqExpr.toString();

		if( condAndExpr != null )
		{
			s += "| " + "&&\n";
			s += "| " + condAndExpr.toString();
		}

		for( String st : s.split( "\n" ) )
			ret += "| " + st + "\n";

		return ret;
	}
	
	public String getType() throws SemanticException {
		
		if(condAndExpr != null)
			return("boolean");
		return(eqExpr.getType());
		
	}
	
	public void check() throws SemanticException {
		
		if(condAndExpr != null){
			
			if(!condAndExpr.getType().equalsIgnoreCase("boolean") || !eqExpr.getType().equalsIgnoreCase("boolean"))
			{
				String details ="One of the children of the conditional expression is not boolean.";
				if( dataInfo != null )
					throw new SemanticException( dataInfo.lineNumber, dataInfo.charNumber, dataInfo.line, details );
				else
					throw new SemanticException( details );
			}
				
			
			eqExpr.check();
			condAndExpr.check();
			
		}else{
			
			eqExpr.check();
			
		}
		
	}
	
}